package com.zyy.smartcity1129.util;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

public class BannerAd extends BannerAdapter<Object, BannerAd.Vh> {
    public BannerAd(List<Object> datas) {
        super(datas);
    }

    @Override
    public BannerAd.Vh onCreateHolder(ViewGroup viewGroup, int i) {
        ImageView imageView=new ImageView(viewGroup.getContext());
        ViewGroup.LayoutParams layoutParams=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        imageView.setLayoutParams(layoutParams);
        return new Vh(imageView);
    }

    @Override
    public void onBindView(BannerAd.Vh vh, Object o, int i, int i1) {
        if(o instanceof String){
            Glide.with(vh.iamge.getContext()).load(Http.base+o).into(vh.iamge);
        }else {
            Glide.with(vh.iamge.getContext()).load(o).into(vh.iamge);
        }

    }

    static class Vh extends RecyclerView.ViewHolder{
        ImageView iamge;
        public Vh(@NonNull ImageView itemView) {
            super(itemView);
            iamge=itemView;
        }
    }
}
